<template>
  <div class="mainForce">
     <pre >
       {{code_data}}
     </pre>
  </div>
</template>
<script>
//https://data.eastmoney.com/zjlx/dpzjlx.html
//主力数据来源，
export default {
  data() {
    return {
       code_data:null,
       code_num:null,
    };
  },
  created() {
    this.getData();
  },
  components: {},
  mounted() {
  },
  methods: {
    async getEndData(add_data) {
      var url1 =
        "https://www.dayfund.cn/ajs/ajaxdata.shtml?showtype=getfundvalue&fundcode=014064";
      await this.$axios.get(url1).then((res) => {
        let result = res.data.split('|'); // 按 | 分割字符串
        result={
          time:result[9],
          num:parseFloat(result[5]),
        }
        if(add_data[add_data.length-1].time!=result.time){
          result.num=result.num+add_data[add_data.length-1].num;
          add_data.push(result);
        }
        console.log(result,add_data);

      });
    },
    async getData() {
      var url1 =
        "https://gushitong.baidu.com/opendata?resource_id=5824&query=014064&new_need_di=1&source=qieman&m=110&t=ai&finClientType=pc";

      await this.$axios.get(url1).then((res) => {
         const data=res.data.Result[0].DisplayData.resultData.tplData.series[0].value;
 
          // 1. 按分号分割字符串，去除末尾空元素
          const items = data.split(';').filter(item => item !== '');
          // 2. 转换为目标数组格式
          const result = items.map(item => {
            // 按逗号分割日期和数值
            const [time, rawNum] = item.split(',');
            // 提取数值并去除符号（+和%）
            const num = Number(rawNum.replace(/[+%]/g, '')); // 转换为数字类型
            return { time, num };
          });
           console.log(result);
           this.getEndData(result)
      });
    },
  },
};
</script>